﻿package com.UIcomponent
{
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.display.MovieClip;
	
	/**
	 * 用Movieclip制作的按钮基类
	 * */
	public class MyButtonBase extends MovieClip
	{
		public function MyButtonBase()
		{
			this.gotoAndStop(1);
			this.buttonMode = true;
			this.mouseChildren = false;
			addListeners();
		}
		
		
		private function addListeners():void
		{
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT,onMouseHandler);
			this.addEventListener(MouseEvent.MOUSE_DOWN,onMouseHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,onMouseHandler);
			//this.addEventListener(MouseEvent.CLICK,onMouseHandler);
			this.addEventListener(Event.REMOVED_FROM_STAGE,onHide);
		}
		
		
		private function onHide(e:Event):void
		{
			this.gotoAndStop(1);
		}
		
		
		private function onMouseHandler(e:MouseEvent):void
		{
			switch(e.type)
			{
				case MouseEvent.MOUSE_OVER:
					this.gotoAndStop(2);
					break;	
				case MouseEvent.MOUSE_DOWN:
					this.gotoAndStop(3);
					//break;
				case MouseEvent.CLICK:
				//	this.gotoAndPlay(3);
				//	this.gotoAndStop(1);
					break;
				case MouseEvent.MOUSE_UP:
				case MouseEvent.MOUSE_OUT:
					this.gotoAndStop(1);
					break;	
				default:
					break;
			}
		}
		
		
		public function removeListeners():void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER,onMouseHandler);
			this.removeEventListener(MouseEvent.MOUSE_OUT,onMouseHandler);
			//this.removeEventListener(MouseEvent.CLICK,onMouseHandler);
			this.removeEventListener(MouseEvent.MOUSE_DOWN,onMouseHandler);
			this.removeEventListener(MouseEvent.MOUSE_UP,onMouseHandler);
		}
	}
}